package com.ruoyi.redisDemo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/redis")
public class RedisTestController {
    @Autowired
    private StringRedisTemplate redisTemplate;

    @GetMapping("/setRedis")
    public String testRedisSet(){
        redisTemplate.opsForValue().set("name","gaoyn",120, TimeUnit.SECONDS);

        return "OK";
    }
    @GetMapping("/getRedis")
    public String testRedisGet(){
        String name = redisTemplate.opsForValue().get("name");
        return name;
    }

}
